package com.xy.staticproxy;

/**
 * @author 谢阳
 * @version 1.8.0_131
 * @date 2022/6/15 15:12
 * @description
 */
public class TeacherDaoProxy implements ITeacherDao{
    // 被代理对象
    private ITeacherDao iTeacherDao;

    public TeacherDaoProxy(ITeacherDao iTeacherDao) {
        this.iTeacherDao = iTeacherDao;
    }

    public TeacherDaoProxy() {
        try {
            iTeacherDao =(ITeacherDao) this.getClass().getClassLoader().loadClass("com.xy.staticproxy.TeacherDao").newInstance();
        } catch (Exception e) {
            System.err.println(e.getMessage());
        }
    }

    /**
     * 上课前
     */
    public void preTeach() {
        System.out.println("你们老师生病了, 我来代一节课...");
    }

    @Override
    public void teach() {
        preTeach();
        iTeacherDao.teach();
        afterTeach();
    }


    /**
     * 上课后
     */
    private void afterTeach() {
        System.out.println("下课了, 同学们有缘再见...");
    }
}
